/*! ******************************************************************************
 *
 * Pentaho
 *
 * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com
 *
 * Use of this software is governed by the Business Source License included
 * in the LICENSE.TXT file.
 *
 * Change Date: 2029-07-20
 ******************************************************************************/


package org.pentaho.platform.api.engine;

import org.pentaho.platform.api.repository.IContentItem;
import org.pentaho.platform.api.scheduler.BackgroundExecutionException;
import org.pentaho.platform.api.scheduler.IJobDetail;

import java.util.List;

public interface IBackgroundExecution {

  public static final String BACKGROUND_ACTION_NAME_STR = "background_action_name"; //$NON-NLS-1$

  public static final String BACKGROUND_SUBMITTED = "background_submit_time"; //$NON-NLS-1$

  public static final String DEFAULT_USER_NAME = "SYSTEM"; //$NON-NLS-1$

  /**
   * Queues the action specified in the request parameters for execution in the background
   * 
   * @param userSession
   *          IPentahoSession of the session executing in background
   * @param parameterProvider
   *          Provides the parameters containing the action to execute in the background
   * @return String response that will be used for user feedback.
   */
  public String backgroundExecuteAction( IPentahoSession userSession, IParameterProvider parameterProvider )
    throws BackgroundExecutionException;

  /**
   * Gets the list of items scheduled for background execution, and those currently executing
   * 
   * @param userSession
   *          The usersession
   * @return List of scheduled/executing jobs
   */
  public List<IJobDetail> getScheduledAndExecutingBackgroundJobs( IPentahoSession userSession )
    throws BackgroundExecutionException;

  /**
   * Removes the content generated by background execution
   * 
   * @param contentGUID
   *          The GUID of the content generated
   * @param userSession
   *          The user session
   */
  public void removeBackgroundExecutedContentForID( String contentGUID, IPentahoSession userSession );

  /**
   * Gets the content generated by background execution
   * 
   * @param contentGUID
   *          The GUID for the content
   * @param userSession
   *          The user session
   * @return IContentItem pointing to the generated content
   */
  public IContentItem getBackgroundContent( String contentGUID, IPentahoSession userSession );

  /**
   * Gets a list of content GUIDs of background executed jobs
   * 
   * @param userSession
   *          User session
   * @return List of executed content ids
   */
  public List<IContentItem> getBackgroundExecutedContentList( IPentahoSession userSession );

  /**
   * This provides an entry point for tracking the created background execution task
   * 
   * @param userSession
   * @param GUID
   */
  public void trackBackgroundExecution( IPentahoSession userSession, String GUID );

  /**
   * Returns the output handler for content, specific to the implementation of the background execution helper.
   * 
   * @param location
   *          Location for the content
   * @param fileName
   *          File name for the content
   * @param solutionName
   *          Solution name
   * @param userSession
   *          IPentahoSession of the caller
   * @param parameterProvider
   *          parameter provider containing request parameters
   * @return IOutputHandler implementation for storing the content.
   */
  public IOutputHandler getContentOutputHandler( String location, String fileName, String solutionName,
      IPentahoSession userSession, IParameterProvider parameterProvider );

}
